home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / quikc21.zip / QBENCH.C < prev    next >
Text File  |  1989-07-06  |  13KB  |  436 lines

  1. /*===========================================================================*\
  2. | QBENCH.C                                                  ver 2.1, 07-06-89 |
  3. |                                                                             |
  4. | Produces a "screens/second" table for QWIKC Screen Utilities.               |
  5. |                                                                             |
  6. | I'm not trying to support this program, so don't expect it to be            |
  7. | perfect.  It will just give you a good feel for speed.  The time is         |
  8. | adjusted for an average 8 second test for each condition - total of 56      |
  9. | seconds.  For more accurate results, change test_time to 16.  Or for a      |
  10. | quicker but less accurate test, change test_time to 2.                      |
  11. | Be sure to see how fast virtual screens are!                                |
  12. | Also try this out in a multi-tasking environment.                           |
  13. | Test is for 80x25 screens only.                                             |
  14. |                                                                             |
  15. |  Copyright (c) 1988,1989 by James H. LeMay, All rights reserved.            |
  16. |                                                                             |
  17. |  Conversion to C by Jordan Gallagher / Wisdom Research                      |
  18. \*===========================================================================*/
  19.  
  20. #include <stdio.h>
  21. #include <conio.h>
  22. #include <string.h>
  23. #include <ctype.h>
  24. #include <process.h>
  25. #include <stdlib.h>
  26.  
  27. #include "qwikc21.h"
  28. #include "timerd12.h"
  29.  
  30. enum attrs {
  31.     attr,
  32.     noattr
  33. };
  34.  
  35. enum procs {
  36.     qwrites,
  37.     qfills,
  38.     qattrs,
  39.     qstores,
  40.     qscrolls
  41. };
  42.  
  43. #define test_time 8  /* test time in seconds for each case.  8 gives +/- 1% */
  44.  
  45. int      attrib;
  46. int      count;
  47. unsigned screens;
  48. char     row;
  49. char     col;
  50. char     rows;
  51. char     cols;
  52. float    scrpersec[5][2];
  53. char     strng[81];
  54. int      proc;
  55. int      a;
  56. FILE     *fv;
  57. int      todisk;
  58. int      tovirtual;
  59. char     ch;
  60. vscr_t   oldscr;
  61. unsigned scr1[4000];
  62. unsigned scr2[4000];
  63.  
  64. char names[5][80] =
  65. { " qwrite-     ", " qfill-      ", " qattr-      ",
  66.   " qstore-     ", " qscroll-    " };
  67.  
  68.  
  69. /******************************| check_zenith |*****************************\
  70. Since Zenith doesn't have snow on any CGAs, turn off snow checking.
  71. \***************************************************************************/
  72. void check_zenith(void)
  73. {
  74.     char tmp[10];
  75.  
  76.     movedata( 0xF000u, 0x800Cu, (unsigned)(((char far *)tmp)+1),
  77.                                 (unsigned)((char far *)tmp),     8 );
  78.     if(qsnow && (strncmp( tmp, "ZDS CORP", 8 )) == 0) {
  79.         qsnow=0;
  80.         cardsnow=0;
  81.     }
  82. }
  83.  
  84.  
  85. /********************************| clearscr |*******************************\
  86. Clears the screen using the yellow on black attribute.
  87. \***************************************************************************/
  88. void clearscr(void)
  89. {
  90.     qfill( 1, 1, crt_rows, crt_cols, WHITE+BLUE_BG, ' ' );
  91. }
  92.  
  93.  
  94. /*******************************| timertest |*******************************\
  95. Clears the screen using the yellow on black attribute.
  96. \***************************************************************************/
  97. void timertest(void)
  98. {
  99.     unsigned char tests=0;
  100.  
  101.     timer( T_START );
  102.     do {
  103.         for(count=0; count<screens; count++)
  104.             for(row=1; row<=25; row++)
  105.                 qwrite( row, 1, YELLOW, strng );
  106.         timer(T_STOP);
  107.         tests++;
  108.     } while( elapsed_time < 1.0 );
  109.     screens = screens*tests*test_time/elapsed_time;
  110. }
  111.  
  112. /********************************| checktime |******************************\
  113. Checks the timer.
  114. \***************************************************************************/
  115. void check_time(void)
  116. {
  117.     char str2[81];
  118.  
  119.     if(qsnow)
  120.          screens=8;        /* First guess for screens for 1 second test */
  121.     else screens=80;
  122.     if(tovirtual)
  123.         screens=2;
  124.  
  125.     strcpy( str2, "TimerTest " );
  126.     for(count=0; count < 8; count++) {         /* copy 8 times */
  127.         strcat( strng, str2 );
  128.     }
  129.     timertest();
  130. }
  131.  
  132.  
  133. /*****************************| assemble_strng |****************************\
  134. Sets up a string for displaying based on the functions which are currently
  135. being tested, and whether or not they are writing using attributes.
  136. \***************************************************************************/
  137. void assemble_strng( int proc, int attrib )
  138. {
  139.     strcpy( strng, names[proc] );
  140.  
  141.     if(qsnow) {
  142.         strcat( strng, " Wait    " );
  143.     } else {
  144.         strcat( strng, " No Wait " );
  145.     }
  146.  
  147.     if(attrib == SAMEATTR) {
  148.         strcat( strng, " No Attr " );
  149.     } else {
  150.         strcat( strng, " w/ Attr " );
  151.     }
  152.  
  153.     memset( &strng[31], proc+49, 49 );
  154.     strng[80]=0;                             /* null-terminate */
  155. }
  156.  
  157.  
  158. /******************************| time_writing |*****************************\
  159. Times screen writes and fills.
  160. \***************************************************************************/
  161. void time_writing( int proc, int attrib )
  162. {
  163.     int a;
  164.  
  165.     clearscr();
  166.  
  167.     if(attrib == SAMEATTR) {
  168.         qattr( 1, 1, crt_rows, crt_cols, LIGHTGRAY );
  169.         a=noattr;
  170.     } else a=attr;
  171.  
  172.     assemble_strng( proc, attrib );
  173.  
  174.     switch(proc) {
  175.         case qwrites:
  176.             timer( T_START );
  177.  
  178.             for(count=1; count <= screens; count++)
  179.                 for(row=1; row <= 25; row++)
  180.                     qwrite( row, 1, attrib, strng );
  181.  
  182.             timer( T_STOP ); break;
  183.  
  184.         case qfills:
  185.             timer( T_START );
  186.  
  187.             for(count=1; count <= screens; count++)
  188.                 qfill( 1, 1, 25, 80, attrib, 'f' );
  189.  
  190.             timer( T_STOP ); break;
  191.  
  192.         case qattrs:
  193.             qfill( 1, 1, 25, 80, attrib, 'a' );
  194.             timer( T_START );
  195.  
  196.             for(count=1; count <= screens; count++)
  197.                 qattr( 1, 1, 25, 80, attrib );
  198.  
  199.             timer( T_STOP ); break;
  200.     }
  201.  
  202.     if(elapsed_time != 0.0)
  203.         scrpersec[proc][a] = screens / elapsed_time;
  204. }
  205.  
  206.  
  207. /*******************************| time_moving |*****************************\
  208. Times screen block moves.
  209. \***************************************************************************/
  210. void time_moving( int proc, int attrib )
  211. {
  212.     assemble_strng( proc, attrib );
  213.  
  214.     for(row=1; row <= 25; row++)
  215.         qwrite( row, 1, attrib, strng );
  216.  
  217.     switch(proc) {
  218.         case qstores:
  219.             timer( T_START );
  220.  
  221.             for(count=1; count <= screens; count++)
  222.                 qstoretomem( 1, 1, 25, 80, scr2 );
  223.  
  224.             timer( T_STOP ); break;
  225.  
  226.         case qscrolls:
  227.             timer( T_START );
  228.  
  229.             for(count=1; count <= screens; count++)
  230.                 qscrollup( 1, 1, 25, 80, SAMEATTR );
  231.  
  232.             timer( T_STOP ); break;
  233.     }
  234.  
  235.     scrpersec[proc][attr] = screens / elapsed_time;
  236. }
  237.  
  238.  
  239. /*******************************| getchoice |*******************************\
  240. Gets input from user.
  241. \***************************************************************************/
  242. char getchoice( char *msg, char answer1, char answer2 )
  243. {
  244.     clearscr();
  245.     qwritec( 12, 1, crt_cols, SAMEATTR, msg );
  246.     gotoeos();
  247. #ifdef __TURBOC__
  248.     while((ch=toupper(getch())) != answer1 && ch != answer2 && ch != 13);
  249. #else
  250.     while((ch=getch(),ch=toupper(ch)) != answer1 && ch != answer2 && ch != 13);
  251. #endif
  252.     return(ch==answer2);
  253. }
  254.  
  255.  
  256. /**********************************| init |*********************************\
  257. Initialize QBENCH.
  258. \***************************************************************************/
  259. void init(void)
  260. {
  261.     qinit();
  262.     check_zenith();
  263.     setmultitask();
  264. #ifdef __TURBOC__
  265.     if(inmultask) directvideo=0;
  266.     textattr(WHITE+BLUE_BG);
  267. #endif
  268.     clearscr();
  269. }
  270.  
  271.  
  272. /******************************| askquestions |*****************************\
  273. \***************************************************************************/
  274. void askquestions(void)
  275. {
  276.     if(qsnow) {